<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>检查字符串在指定的编码里是否有效</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.mbstring.html">« 多字节字符串 函数</a></li>
      <li style="float: right;"><a href="function.mb-chr.html">mb_chr »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.mbstring.html">多字节字符串 函数</a></li>
    <li>检查字符串在指定的编码里是否有效</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.mb-check-encoding" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_check_encoding</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.4.3, PHP 5 &gt;= 5.1.3, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mb_check_encoding</span> &mdash; <span class="dc-title">检查字符串在指定的编码里是否有效</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mb-check-encoding-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_check_encoding</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$var</code><span class="initializer"> = <strong><code>null</code></strong></span></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$encoding</code><span class="initializer"> = mb_internal_encoding()</span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   检查指定的字节流在指定的编码里是否有效。它能有效避免所谓的“无效编码攻击（Invalid Encoding Attack）”。
  </p>
  <p class="para">
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-check-encoding-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">var</code></dt>

     <dd>

      <p class="para">
       要检查的字节流。如果省略了这个参数，此函数会检查所有来自最初请求所有的输入。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">encoding</code></dt>

     <dd>

      <p class="para">
       期望的编码。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mb-check-encoding-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


</div></div></div></body></html>